﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;
using xiaodingmarket_Domain.Models;

namespace xiaodingmarket_Infra_Data.Mapping
{
    public class CommodityMap : IEntityTypeConfiguration<Commodity>
    {
        public void Configure(EntityTypeBuilder<Commodity> builder)
        {
            builder.Property(p => p.endtime).HasColumnType("DATETIME2")
                .IsRequired(false);
                //.HasDefaultValueSql("GETDATE()");
            builder.HasIndex(p => p.Category);//单列索引

            builder.HasOne(p => p.CommodityDetail).WithOne(p => p.commodity)
                .HasForeignKey<CommodityDetail>(k => k.Id)
                .OnDelete(DeleteBehavior.Cascade);//设置级联删除   
        }
    }
    public class CommodityDetailMap : IEntityTypeConfiguration<CommodityDetail>
    {
        public void Configure(EntityTypeBuilder<CommodityDetail> builder)
        {
            builder.Property(p => p.ModifyTime).HasColumnType("DATETIME2")
                .IsRequired(false);
            builder.Property(p => p.LogTime).HasColumnType("DATETIME2")
                .IsRequired(false);
            builder.Property(p => p.Price).HasColumnType("decimal(18,2)");
            //.HasDefaultValueSql("GETDATE()");
            builder.HasIndex(p => p.StudentId);//单列索引

            
        }
    }
}
